let that //that用来存放this指针
class Tab {
  //构造函数
  constructor(a) {
    // 传参获取tab
    that = this
    this.alltab = document.querySelector(a)
    this.allslis = this.alltab.querySelectorAll('.firstNav li')
    this.sections = this.alltab.querySelectorAll('.tabscon sections')
    this.init()
  }

  init() {
    this.allslis.forEach((item, index) => {
      item.index = index
      item.addEventListener('click', this.togglesTab)
    })
  }

  //清除类名
  clearclassname() {
    that.allslis.forEach((item) => (item.className = ''))
    that.sections.forEach((item) => (item.className = ''))
  }
  togglesTab() {
    that.clearclassname()
    this.className = 'liactive'
    that.sections[this.index]
  }
}

new Tab('#tab')
